﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-transparent.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>工序能力看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .header-title {
      font-size: 24px !important;
    }

    #queryZone .el-form-item__label {
      color: #fff;
    }

    .el-form-item {
      margin-bottom: 0 !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <el-row>
        <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
        <el-col :span="12" class="header-title">{{queryInfo.factoryname}}工序能力看板</el-col>
        <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
      </el-row>

      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        id="queryZone">
        <el-form-item label="筛选时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="组织结构:" prop="selectOrg">
          <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
            v-model="queryInfo.selectOrg" clearable style="width:260px;">
          </el-cascader>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:200px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:360px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="searchData">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="exportDetail">导出</el-button>
          <el-button type="success" icon="el-icon-setting" size="small" @click="openInsertSpecItemsDialog">工序设置
          </el-button>
        </el-form-item>
      </el-form>

      <!-- 工序参数设置--对话框 -->
      <el-dialog title="工序参数设置" :visible.sync="specItemsObj.dialogVisable" top="10px" width="70%">
        <!-- 表单 -->
        <el-form :model="specItemsObj.queryInfo" :inline="true">
          <el-form-item label="组织结构:" prop="selectOrg">
            <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
              v-model="specItemsObj.queryInfo.selectOrg" clearable style="width:280px;">
            </el-cascader>
          </el-form-item>

          <el-form-item label="工序名称:" prop="specname">
            <el-input v-model.trim="specItemsObj.queryInfo.specname" placeholder="请输入" clearable style="width: 140px;">
            </el-input>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" size="small" icon="el-icon-search" @click="getSpecItems">查询</el-button>
            <el-button type="success" size="small" icon="el-icon-circle-plus-outline"
              @click="addSpecItemObj.dialogVisable = true">添加</el-button>
          </el-form-item>
        </el-form>

        <!-- 表格 -->
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="specItemsObj.dataList" stripe border height="640">
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="操作" width="130">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="dark" content="修改" placement="top-start">
                <el-button type="warning" icon="el-icon-edit" size="mini" @click="openUpdateSpecItemDialog(scope.row)">
                </el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="删除" placement="top-start">
                <el-button type="danger" icon="el-icon-delete" size="mini" @click="deleteData(scope.row)">
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="唯一id" prop="id" width="100" v-if="false"></el-table-column>
          <el-table-column label="factoryid" prop="factoryid" width="100" v-if="false"></el-table-column>
          <el-table-column label="workcenterid" prop="workcenterid" width="100" v-if="false"></el-table-column>
          <el-table-column label="工序" prop="specname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="目标工时" prop="threshold" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="分厂" prop="factoryname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="工区" prop="workcentername" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="颗粒度" prop="orgtype" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="启用状态" prop="status" width="100">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.status" active-text="启用" inactive-text="" @change="changeStatus(scope.row)">
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column label="创建人" prop="createemployee" width="70" show-overflow-tooltip></el-table-column>
          <el-table-column label="创建时间" prop="createdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="修改人" prop="lastchangeemployee" width="70" show-overflow-tooltip></el-table-column>
          <el-table-column label="修改时间" prop="lastchangedate" width="100" :formatter="splitDate"></el-table-column>
        </el-table>
      </el-dialog>

      <!-- 添加工序--对话框 -->
      <el-dialog title="添加工序" :visible.sync="addSpecItemObj.dialogVisable" width="50%" @close="addDialogClosed">
        <el-form :model="addSpecItemObj.addSpecItemForm" :rules="addSpecItemObj.addSpecItemFormRule"
          ref="addSpecItemFormRef" :inline="true">
          <el-form-item label="组织结构:" prop="selectOrg">
            <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
              v-model="addSpecItemObj.addSpecItemForm.selectOrg" clearable style="width:280px;">
            </el-cascader>
          </el-form-item>

          <el-form-item label="工序名称:" prop="specname">
            <el-input v-model.trim="addSpecItemObj.addSpecItemForm.specname" placeholder="请输入" clearable
              style="width: 140px;">
            </el-input>
          </el-form-item>

          <el-form-item label="目标工时:" prop="threshold">
            <el-input-number v-model="addSpecItemObj.addSpecItemForm.threshold" :precision="0" :step="1" :min="0">
            </el-input-number>
          </el-form-item>
        </el-form>
        <!-- 弹出窗底下按钮 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="addSpecItemObj.dialogVisable = false">取 消</el-button>
          <el-button type="primary" @click="addBtnConfirm" :loading="addSpecItemObj.loading">确 定</el-button>
        </span>
      </el-dialog>

      <!-- 修改工序--对话框 -->
      <el-dialog title="修改工序" :visible.sync="updateSpecItemObj.dialogVisable" width="50%" @close="updateDialogClosed">
        <el-form :model="updateSpecItemObj.updateSpecItemForm" :rules="updateSpecItemObj.updateSpecItemFormRule"
          ref="updateSpecItemFormRef" :inline="true">
          <el-form-item label="组织结构:" prop="selectOrg">
            <el-cascader :options="orginazition" :props="{ checkStrictly: true}" ref="orginazitionRef"
              v-model="updateSpecItemObj.updateSpecItemForm.selectOrg" clearable style="width:280px;">
            </el-cascader>
          </el-form-item>

          <el-form-item label="工序名称:" prop="specname">
            <el-input v-model.trim="updateSpecItemObj.updateSpecItemForm.specname" placeholder="请输入" clearable
              style="width: 140px;">
            </el-input>
          </el-form-item>

          <el-form-item label="目标工时:" prop="threshold">
            <el-input-number v-model="updateSpecItemObj.updateSpecItemForm.threshold" :precision="0" :step="1" :min="0">
            </el-input-number>
          </el-form-item>
        </el-form>
        <!-- 弹出窗底下按钮 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="updateSpecItemObj.dialogVisable = false">取 消</el-button>
          <el-button type="primary" @click="updateBtnConfirm" :loading="updateSpecItemObj.loading">确 定</el-button>
        </span>
      </el-dialog>

      <!-- 柱状图区域 -->
      <dv-border-box-11 title="工序工时统计" ref="borderBox">
        <div style="height: 260px;padding-top: 40px;width: 100%;" id="thisMonthChart"></div>
      </dv-border-box-11>

      <!-- 表格 -->
      <dv-border-box-11 title="各批次已开卡工时" ref="datagrid">
        <div id="datagrid" style="padding: 30px;padding-top:60px;padding-bottom:10px;">
          <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
            element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border ref="table">
            <el-table-column type="index" width="50"></el-table-column>
            <el-table-column label="零件号" prop="productname" width="100" show-overflow-tooltip></el-table-column>
            <el-table-column label="零件/批次号" prop="containername" width="200" show-overflow-tooltip></el-table-column>
            <el-table-column label="主制工区" prop="fromworkcentername" width="140" show-overflow-tooltip></el-table-column>
            <el-table-column label="在制数" prop="qty" width="100"></el-table-column>
            <el-table-column label="开始时间" prop="startdate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column label="结束时间" prop="enddate" width="100" :formatter="splitDate"></el-table-column>
            <el-table-column v-for="col in colums" :label="col.label" :key="col.value" :prop="col.value" width="95">
              <template slot-scope="scope">
                <span v-for="i in scope.row[col.value]">
                  <span v-if="i.worktime">{{i.worktime}}</span>
                  <span v-else>0</span>
                </span>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryInfo.currentPage" :page-sizes="[queryInfo.pageSize]" :page-size="queryInfo.pageSize"
            layout="prev,pager,next,jumper,sizes,total" :total="total">
          </el-pagination>
          <el-backtop></el-backtop>
        </div>
      </dv-border-box-11>

      <!-- 工序已开卡明细 -->
      <el-dialog :title="chartDetail.title" :width="'90%'" top="10px" :center="'center'"
        :visible.sync="chartDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="chartDetail.dataList" stripe border>
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="开始时间" prop="startdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="结束时间" prop="enddate" width="100" :formatter="splitDate" sortable></el-table-column>
          <el-table-column label="批次号" prop="containername" width="200" show-overflow-tooltip sortable>
          </el-table-column>
          <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="当前工序" prop="currentspec" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="工序" prop="opdesc" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="单位工时" prop="durationperunit" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="派工人" prop="dispatchemployeename" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="派工时间" prop="dispatchdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="报工人" prop="reportemployeename" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="报工时间" prop="reportdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="报工数量" prop="reportqty" width="100"></el-table-column>
          <el-table-column label="检验人" prop="checkemployeename" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="检验时间" prop="checkdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="状态" prop="status" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag effect="dark" v-if="scope.row.status === '已完工'" type="success">{{scope.row.status}}</el-tag>
              <el-tag effect="dark" v-else-if="scope.row.status === '待检验'" type="danger">{{scope.row.status}}</el-tag>
              <el-tag effect="dark" v-else-if="scope.row.status === '待报工'" type="warning">{{scope.row.status}}</el-tag>
              <el-tag effect="dark" v-else type="info">{{scope.row.status}}</el-tag>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination @current-change="handleChartDetailCurrentChange"
          :current-page="chartDetail.queryInfo.currentPage" :page-sizes="[chartDetail.queryInfo.pageSize]"
          :page-size="chartDetail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="chartDetail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js';
    import { exportExcelData, getParams, fetchSuggestion, getUserWhiteList } from '../Scripts/hooks/useCommonMethod.js';
    import { prevMonth, thisMonth } from '../Scripts/hooks/useDateShortCut.js';
    import { getUserInfo, getFactoryInfo } from '../Scripts/hooks/fetchAPI.js';
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: {
          factoryid: '',
          factoryname: '',
          productname: '',
          containername: '',
          selectdate: '',
          selectOrg: [],
          currentPage: 1,
          pageSize: 10
        },
        total: 0,
        dataList: [],
        colums: [],
        rules: {
          selectdate: [{ required: true, message: '筛选时间不能为空', trigger: 'change' }],
          selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }]
        },
        pickerOptions: { shortcuts: [prevMonth, thisMonth] },
        orginazition: [],//组织结构
        // 已维护工序
        specItemsObj: {
          dialogVisable: false,
          queryInfo: { selectOrg: [], specname: '' },
          dataList: []
        },
        // 添加工序
        addSpecItemObj: {
          dialogVisable: false,
          loading: false,
          addSpecItemForm: { selectOrg: '', specname: '', threshold: '', id: '' },
          addSpecItemFormRule: {
            selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }],
            specname: [{ required: true, message: '工序名称不能为空', trigger: 'blur' }],
            threshold: [{ required: true, message: '目标工时不能为空', trigger: 'blur' }]
          }
        },
        // 修改工序
        updateSpecItemObj: {
          dialogVisable: false,
          loading: false,
          updateSpecItemForm: { selectOrg: '', specname: '', threshold: '', id: '' },
          updateSpecItemFormRule: {
            selectOrg: [{ required: true, message: '组织结构不能为空', trigger: 'change' }],
            specname: [{ required: true, message: '工序名称不能为空', trigger: 'blur' }],
            threshold: [{ required: true, message: '目标工时不能为空', trigger: 'blur' }]
          }
        },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff' },
        // 已开卡批次明细
        chartDetail: { dialogVisiable: false, queryInfo: { specname: '', currentPage: 1, pageSize: 12 }, dataList: [], title: '', total: 0 }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback, triggerLength: 2 })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback, triggerLength: 2 })
        },
        // 获取工装工具厂 `分厂/工区` 组织结构
        async getGZOrginazition() {
          const { data: res } = await axios.post('../handler/board/GZSpecCapacityDashBoardV2.ashx?action=getMESOrginazition', {
            type: 'getMESOrginazition', factoryCode: '604'
          })
          this.orginazition = res.data;
        },
        // 查询已维护工序
        async getSpecItems() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/GZSpecCapacityDashBoardV2.ashx?action=getSpecItems', {
            type: 'getSpecItems', ...this.specItemsObj.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.specItemsObj.dataList = data.map(item => {
            return { ...item, status: item.status === 1 }; //将【启用状态】由字符串变更为布尔值
          })
        },
        // 打开新增对话框
        async openInsertSpecItemsDialog() {
          const employeeid = getParams('uid');
          // 获取用户权限白名单
          const pageurl = window.location.pathname.split('/')[3];
          const whiteList = await getUserWhiteList(pageurl, this.$message);

          if (whiteList.indexOf(employeeid) === -1) {
            this.formDisabled = true;
            return this.$message.error('当前用户没有使用权限');
          }

          this.specItemsObj.dialogVisable = true;
          this.getSpecItems();
        },
        // 打开修改对话框
        openUpdateSpecItemDialog(row) {
          const { specname, threshold, id, factoryid, workcenterid } = row;
          let selectOrg = [];
          if (workcenterid) {
            selectOrg = [factoryid, workcenterid];
          } else {
            selectOrg = [factoryid];
          }
          this.updateSpecItemObj.dialogVisable = true;
          this.updateSpecItemObj.updateSpecItemForm = { selectOrg, specname, threshold, id };
        },
        // 检查待新增工序是否已存在
        async checkIsExist(obj) {
          const { data: { data, meta, total } } = await axios({
            method: 'POST',
            url: '../handler/board/GZSpecCapacityDashBoardV2.ashx?action=checkIsExist',
            data: { type: 'checkIsExist', ...obj }
          })
          return total > 0;
        },
        // 添加对话框[确认]点击
        addBtnConfirm() {
          this.$refs['addSpecItemFormRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空!');
            } else {
              this.addSpecItemObj.loading = true;
              // 新增前 先判断 是否存在相同数据
              const isExist = await this.checkIsExist({ ...this.addSpecItemObj.addSpecItemForm });
              if (isExist) {
                this.addSpecItemObj.loading = false;
                return this.$message.error('数据已存在，不能重复添加');
              }

              const { data: { data, meta, total } } = await axios({
                method: 'POST',
                url: '../handler/board/GZSpecCapacityDashBoardV2.ashx?action=insertData',
                data: { type: 'insertData', ...this.addSpecItemObj.addSpecItemForm, employeeid: getParams("uid") }
              });

              this.addSpecItemObj.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }

              if (total > 0) {
                this.$message.success('新增成功');
                this.addSpecItemObj.addSpecItemForm.specname = "";
                this.getSpecItems();
              } else {
                return this.$message.error('新增失败');
              }
            }
          });
        },
        // 修改对话框[确认]点击
        updateBtnConfirm() {
          this.$refs['updateSpecItemFormRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空!');
            } else {
              this.updateSpecItemObj.loading = true;
              // 新增前 先判断 是否存在相同数据
              const isExist = await this.checkIsExist({ ...this.updateSpecItemObj.updateSpecItemForm });
              if (isExist) {
                this.updateSpecItemObj.loading = false;
                return this.$message.error('数据已存在，不能修改');
              }

              const { data: { data, meta, total } } = await axios({
                method: 'POST',
                url: '../handler/board/GZSpecCapacityDashBoardV2.ashx?action=updateData',
                data: { type: 'updateData', ...this.updateSpecItemObj.updateSpecItemForm, employeeid: getParams("uid") }
              });

              this.updateSpecItemObj.loading = false;
              if (meta.status === 500) { return this.$message.error(meta.msg); }

              if (total > 0) {
                this.$message.success('修改成功');
                this.updateSpecItemObj.dialogVisable = false;
                this.getSpecItems();
              } else {
                return this.$message.error('修改失败');
              }
            }
          });
        },
        // 删除数据
        async deleteData(row) {
          const { id } = row;
          // 更新启用状态前确认
          const confirmResult = await this.$confirm('是否确认删除?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).catch(err => err)

          // 取消切换
          if (confirmResult !== 'confirm') { return this.$message.info('已取消删除'); }

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZSpecCapacityDashBoardV2.ashx?action=deleteData', { type: 'deleteData', id });
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.$message.success('删除成功');
          this.getSpecItems();
        },
        // 切换启用状态
        async changeStatus(row) {
          const { id, status } = row;
          const confirmResult = await this.$confirm('是否切换启用状态?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).catch(err => err)

          // 取消切换
          if (confirmResult !== 'confirm') {
            row.status = !row.status;
            return this.$message.info('已取消切换');
          }

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZSpecCapacityDashBoardV2.ashx?action=changeStatus', {
            type: 'changeStatus', id, status, employeeid: getParams("uid")
          });

          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.$message.success('状态切换成功');
          this.getSpecItems();
        },
        // 添加对话框关闭后
        addDialogClosed() {
          this.addSpecItemObj.addSpecItemForm = { selectOrg: '', specname: '', threshold: '', id: '' }
          this.$refs['addSpecItemFormRef'].resetFields();
        },
        // 修改对话框关闭后
        updateDialogClosed() {
          this.updateSpecItemObj.updateSpecItemForm = { selectOrg: '', specname: '', threshold: '', id: '' }
          this.$refs['updateSpecItemFormRef'].resetFields();
        },
        // 查询柱状图数据
        async getChartData() {
          const dom = document.getElementById("thisMonthChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/GZSpecCapacityDashBoardV2.ashx?action=getChartData', {
            type: 'getChartData', ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrSpecName = [], arrThreshold = [], arrStartWorktime = [], arrWorktime = [];
          for (const i of data) {
            arrSpecName.push(i.specname);
            arrThreshold.push(i.threshold);
            arrStartWorktime.push(i.worktime);
            arrWorktime.push(i.threshold - i.worktime >= 0 ? (i.threshold - i.worktime) : (i.worktime - i.threshold));
          }

          let option = barOption({ showDataZoom: true, startValue: 0, endValue: 10 });
          option.legend.data = ['计划工时', '已开卡工时', '差异工时'];//设置图例文字
          option.xAxis.data = arrSpecName;
          option.yAxis[1].show = false;
          option.grid.left = '2%';
          option.grid.right = '2%';
          option.grid.bottom = '13%';

          option.series[0].barGap = '0.3';
          option.series[0] = _.merge(option.series[0], {
            name: '计划工时',
            data: arrThreshold,
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '已开卡工时',
            data: arrStartWorktime,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          option.series[2] = _.merge(_.cloneDeep(option.series[0]), {
            name: '差异工时',
            data: arrWorktime,
            label: { color: 'inherit' },//lable继承 `柱状图` 颜色
            itemStyle: {
              color: params => {
                const { name, value } = params;
                const { threshold, worktime } = data.filter(i => i.specname === name)[0];
                return worktime > threshold ? 'red' : 'yellow';
              }
            }
          });

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.borderBox.initWH(); chart.resize(); }, 300);
          chart.on('click', params => {
            const { seriesName, name, value } = params;
            if (value == 0) { return; }
            this.chartDetail.queryInfo.currentPage = 1;
            this.chartDetail.queryInfo.specname = name;//工序名称
            this.chartDetail.title = `【${name}】已开卡批次明细`;
            this.chartDetail.dialogVisiable = true;
            this.getChartDetail();
          })
        },
        // 查询表格数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/GZSpecCapacityDashBoardV2.ashx?action=getData', {
            type: 'getData', ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg) }
          if (data.length === 0) { this.dataList = []; return; }
          this.colums = [];
          this.dataList = data;
          this.total = total;
          let colums = Object.keys(data[0]);
          for (const i of colums) {
            if (!(i === 'productname' || i === 'containername' || i === 'fromworkcentername' || i === 'startdate' || i === 'enddate' || i === 'tttttrn' || i === 'qty')) {
              this.colums.push({ value: i, label: i })
            }
          }
          this.$refs["table"].doLayout();
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.datagrid.initWH(); }, 300);
        },
        // 查询已开卡明细
        async getChartDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/GZSpecCapacityDashBoardV2.ashx?action=getChartDetail', {
            type: 'getChartDetail', ...this.queryInfo, ...this.chartDetail.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.chartDetail.dataList = data;
          this.chartDetail.total = total;
        },
        // 查询按钮点击
        searchData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) { return this.$message.error('必填项不能为空'); }
            this.getChartData();
            this.getData();
          })
        },
        // 导出
        exportDetail() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) { return this.$message.error('必填项不能为空') }
            const config = {
              url: '../handler/board/GZSpecCapacityDashBoardV2.ashx?action=exportExcel',
              data: { type: 'exportExcel', ...this.queryInfo }
            }
            exportExcelData(config, this);
          });
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSizeChange(pageSize) {
          this.queryInfo.pageSize = pageSize;
          this.getData();
        },
        handleChartDetailCurrentChange(newPage) {
          this.chartDetail.queryInfo.currentPage = newPage;
          this.getChartDetail();
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfThisMonth, endOfThisMonth];
        this.queryInfo.selectOrg = [Decrypt(getParams("factoryid"))];
        this.getGZOrginazition();
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        const factoryInfo = await getFactoryInfo({ factoryid: Decrypt(getParams('factoryid')), isMapping: '是' });//查询当前分厂信息
        const { factoryid, factoryname } = factoryInfo[0];
        this.queryInfo.factoryname = factoryname;
        this.queryInfo.factoryid = factoryid;
        this.getChartData();
        this.getData();
      }
    })
  </script>
</body>

</html>